package cn.bugstack.springframework.beans.factory.support;
// 抽象类定义模板方法(AbstractBeanFactory)
import cn.bugstack.springframework.beans.BeanException;
import cn.bugstack.springframework.beans.factory.BeanFactory;
import cn.bugstack.springframework.beans.factory.config.BeanDefinition;

// AbstractBeanFactory 首先继承了 DefaultSingletonBeanRegistry，也就具备了使用
//单例注册类方法。
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {
    @Override
    public Object getBean(String name) throws BeanException {
        Object bean = getSingleton(name);
        if (bean != null){
            return bean;
        }
        BeanDefinition beanDefinition = getBeanDefinition(name);
        return createBean(name,beanDefinition);
    }
    protected abstract BeanDefinition getBeanDefinition(String beanName) throws BeanException;

    protected abstract Object createBean(String beanName,BeanDefinition beanDefinition)throws BeanException;
}
